﻿// -----------------------------------------------------------------------
// <copyright file="MenuItem.cs" company="Diddly Squad">
// </copyright>
// -----------------------------------------------------------------------

using System;

namespace DiddlySquat
{
	/// <summary>
	/// Class to represent files in menus
	/// </summary>
	public class FileMenuItem : MenuItem
	{
		/// <summary>
		/// Gets or sets the filename.
		/// </summary>
		/// <value>
		/// The filename.
		/// </value>
		public string Filename { get; set; }

		/// <summary>
		/// Gets or sets the creation date.
		/// </summary>
		/// <value>
		/// The creation date.
		/// </value>
		public DateTime CreationDate { get; set; }

		/// <summary>
		/// Initializes a new instance of the <see cref="FileMenuItem"/> class.
		/// </summary>
		/// <param name="text">The text.</param>
		/// <param name="menuItemType">Type of the menu item.</param>
		public FileMenuItem(string text, Enums.MenuItemType menuItemType) : base(text, menuItemType) {}

		/// <summary>
		/// Creates the file menu item.
		/// </summary>
		/// <param name="filename">The filename.</param>
		/// <returns>Created file menu item</returns>
		public static FileMenuItem CreateFileMenuItem(string filename)
		{
			FileMenuItem ret = new FileMenuItem(filename, Enums.MenuItemType.File);
			var splitted = filename.Split('_');
			var date = splitted[1];
			var time = splitted[2].Substring(0, splitted[2].IndexOf('.')).Replace('-', ':');
			ret.CreationDate = DateTime.Parse(date + " " + time);
			ret.Filename = filename;
			ret.Text = splitted[0] + " Save";
			return ret;
		}
	}
}
